#include "MemLinkRegistry.hpp"
#include <iostream>

int main() {
    MemLinkRegistry registry;

    // 注册主机 A
    registry.registerHost({
        .hostname = "hostA",
        .ip = "192.168.1.10",
        .port = 9000,
        .activeChannels = {}
    });

    // 注册主机 B
    registry.registerHost({
        .hostname = "hostB",
        .ip = "192.168.1.11",
        .port = 9000,
        .activeChannels = {}
    });

    // 分配通道给 hostB
    int ch = registry.assignChannel("hostB");
    std::cout << "✅ Assigned channel " << ch << " to hostB" << std::endl;

    // 查询所有主机
    auto hosts = registry.discoverHosts();
    for (const auto& h : hosts) {
        std::cout << "🔍 Host: " << h.hostname << " IP: " << h.ip << " Channels: ";
        for (int cid : h.activeChannels) std::cout << cid << " ";
        std::cout << std::endl;
    }

    // 释放通道
    registry.releaseChannel("hostB", ch);
    std::cout << "🧹 Released channel " << ch << " from hostB" << std::endl;

    return 0;
}
